<?php
class Line_order_member_model extends CI_Model
{
    private $table = 'line_order_member';
    
    public function insertLineOrderMember($order_id, $postData)
    {
        $adultArray    = array(); //成人
        $childrenArray = array(); //儿童
        if (!empty($postData['adult'])) {
            foreach ($postData['adult'] as $key1 => $adult) {
                if (!empty($adult['visitor_name'])) {
                    $adultArray[$key1]['order_id']        = $order_id;
                    $adultArray[$key1]['credentials']     = $adult['credentials']; //证件类型
                    $adultArray[$key1]['certificate_num'] = $adult['certificate_num']; //证件号
                    $adultArray[$key1]['visitor_name']    = $adult['visitor_name'];
                    $adultArray[$key1]['telephone']       = !empty($adult['telephone']) ? $adult['telephone'] : '';
                    $adultArray[$key1]['birthday']        = isset($adult['birthday']) ? date('Y-m-d H:i:s', strtotime($adult['birthday'])) : date('Y-m-d H:i:s', time());
                    $adultArray[$key1]['sex']             = $adult['sex'];
                    $adultArray[$key1]['is_adult']        = 1;
                }
            }
        }
        
        if (!empty($postData['children'])) {
            foreach ($postData['children'] as $key2 => $children) {
                if (!empty($children['visitor_name'])) {
                    $childrenArray[$key2]['order_id']        = $order_id;
                    $childrenArray[$key2]['credentials']     = $children['credentials'];
                    $childrenArray[$key2]['certificate_num'] = $children['certificate_num'];
                    $childrenArray[$key2]['visitor_name']    = $children['visitor_name'];
                    $childrenArray[$key2]['telephone']       = !empty($children['telephone']) ? $children['telephone'] : '';
                    $childrenArray[$key2]['birthday']        = isset($children['birthday']) ? date('Y-m-d H:i:s', strtotime($children['birthday'])) : date('Y-m-d H:i:s', time());
                    $childrenArray[$key2]['sex']             = isset($children['sex']) ? $children['sex'] : '1';
                    $childrenArray[$key2]['is_adult']        = 2;
                }
            }
        }
        $data = array_merge($adultArray, $childrenArray);
        if (!empty($data)) {
            return $this->db->insert_batch($this->table,$data);
        }
        return true;
    }
    
    
}